<#if invalid??>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>无法创建合同！</strong>
			无效的主合同信息或者系统异常！
		</div>
	</div>
</div>
<#else>
<form class="form-create-task-contract" action="${request.contextPath}/sub-contract/create" method="post" enctype="multipart/form-data">
	<input type="hidden" name="parent.id" value="${parent.id}">
	<input type="hidden" name="status" value="START">
	<input type="hidden" name="type" value="${type}">

	<div class="row">
		<div class="col-md-12">
			<div class="form-group text-center">
				<div class="text-danger" style="font-size: 21px;">创建《${parent.name}》的&lt;${type.value}&gt;</div>
				<small>[No.] ${parent.no}</small>
			</div>
		</div>
	</div>

	<fieldset>
		<legend class="text-primary">基本信息</legend>
		<div class="row">
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								任务书名称
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="name" value="${parent.name}XXX${type.value}" placeholder="最多100个汉字">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								任务书编号
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="no" value="${parent.no}-XXX" placeholder="最多50个字符">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								任务书金额
							</div>
						</div>
						<input type="text" class="form-control not-empty number" name="price" value="${parent.price}" placeholder="只能是数字">
						<div class="input-group-addon">元</div>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								签订日期
							</div>
						</div>
						<input type="text" class="form-control not-empty datetimepicker" name="signDate" data-foot="false" data-format="yyyy-MM-dd" data-time="${.now}" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								实施单位
							</div>
						</div>
						<select class="form-control not-empty" name="companyB">
							<#if companyB??> <#list companyB as cb>
							<option value="${cb}">${cb}</option>
							</#list> </#if>
						</select>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								建设单位
							</div>
						</div>
						<input type="text" class="form-control not-empty" name="companyA" value="${parent.companyB}" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								开工日期
							</div>
						</div>
						<input type="text" class="form-control not-empty datetimepicker" name="contractStart" data-foot="false" data-format="yyyy-MM-dd" placeholder="请填写合同文件中的开工日期" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								竣工日期
							</div>
						</div>
						<input type="text" class="form-control not-empty datetimepicker" name="contractEnd" data-foot="false" data-format="yyyy-MM-dd" placeholder="请填写合同文件中的竣工日期" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								结算方式
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="jiesuanWay" placeholder="最多500个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								付款方式
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="fukuanWay" placeholder="最多500个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								工程内容
							</div>
						</div>
						<textarea rows="3" class="form-control not-empty" name="mainContent" placeholder="最多1000个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								承包范围
							</div>
						</div>
						<textarea rows="3" class="form-control" name="chengbaoFanwei" placeholder="最多1000个汉字"></textarea>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">备注</div>
						</div>
						<textarea rows="3" class="form-control" name="remark" placeholder="最多1000个汉字"></textarea>
					</div>
				</div>
			</div>
		</div>
	</fieldset>

	<fieldset>
		<legend class="text-success">相关文件</legend>
		<div class="row">
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">
								<span class="not-null-star">*</span>
								合同文件
							</div>
						</div>
						<input type="file" class="hidden" name="contractFile" data-suffix=".pdf, .jpeg, .jpg">
						<input type="text" class="form-control not-empty file-show" placeholder="请选择相关文件。格式只能是[.pdf, .jpeg, .jpg]中的一个！" readonly="readonly">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon">
							<div class="form-item-title">附件资料</div>
						</div>
						<input type="file" class="hidden" name="file" data-suffix=".rar, .zip">
						<input type="text" class="form-control file-show" placeholder="请选择附件资料。格式只能是[.rar, .zip]中的一个！" readonly="readonly">
					</div>
				</div>
			</div>
		</div>
	</fieldset>

	<hr style="margin-top: 5px;">
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-sm btn-primary create-contract">确定</div>
			&nbsp;
			<div class="btn btn-sm btn-default" onclick="$.suredy.closeModal();">取消</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		$.suredy.datetimepicker.init();

		$('.create-contract').on('click', function() {
			var form = $('form.form-create-task-contract');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert('新建生产经营任务书失败！\n\n' + (parent.msg || ''));
						$this.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${parent.id}', [ 'div.suredy-tabs' ]);

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('新建生产经营任务书失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
